//加载自定义模块(./表示与本文件在同一级目录下，也可以写成./parseRequest.js，默认不需要写后缀)
var rRequest = require('./app/parseRequest');
//加载node模块
var http = require('http');
var fs = require('fs');
var url = require('url');
var path = require('path');
var queryString = require('querystring');
//创建请求处理对象，用于处理静态文件及动态请求响应
var allReqParse = new rRequest.parseRequest(fs, queryString);
//创建服务器
http.createServer(function(request, response) {
    //获取请求地址
    var requrl = request.url;
    var urlparse = url.parse(requrl);
    //请求路径
    var pathname = urlparse.pathname;
    //pathname+参数
    // var urlpath = urlparse.path;
    //参数
    var query = urlparse.query;
    //同上，但参数前多个？
    // var search = urlparse.search;
    //后缀
    var suffix = path.extname(pathname);
    //控制台显示信息
    // console.log("Request for " + pathname + " received,path is " + urlpath + ",query is" + query + ",search is" + search);
    console.log("Request for " + pathname + "received,后缀是： " + suffix + ",参数: " + query);
    if (suffix != null && suffix.trim() != "") {
        rRequest.parseFile(response, pathname, suffix);
    } else {
        allReqParse.parseRest(response, pathname, query);
    }
    //响应结束
}).listen(8081);
//开启后在控制台显示该服务正在运行
console.log('Server running at http://127.0.0.1:8081/');
